<?php
/**
 * Input XML
 *
 * @category Zwei
 * @package Zwei_Admin
 * @subpackage Elements
 * @version $Id:$
 * @author Rodrigo Riquelme <rodrigo.riquelme.e@gmail.com>
 * @license GNU GPL-v2 http://www.gnu.org/licenses/gpl-2.0.html
 * @since 0.1
 * @link http://code.google.com/p/xml-admin/
 */


class Zwei_Admin_Elements_XmlList extends Zwei_Admin_Elements_Element{
    function edit($i, $j, $display="inline"){
	   $options=$this->options();
	   return "<select style=\"display:$display\" id=\"edit{$i}_{$j}\" name=\"{$this->target}[$i]\">\r\n$options\r\n</select>";
    }

    function display($i, $j){
        $options=$this->options();
        return "<select disabled=\"disabled\" id=\"field{$i}_{$j}\">\r\n$options\r\n</select>";
    }

    function options(){
  	  $options="<option value=\"0\">* None *</option>\r\n";
      $dirs=glob(ROOT.$this->params['PATH'].'/*.xml');
      $selected=array();
 

      $request=new Zwei_Utils_Form();

      if($this->value==null){
      	if(isset($request->{$this->target}))$value=$request->{$this->target};
      	else $value=null;
      }else{
      	$value=$this->value;
      }

	  foreach($dirs as $dir){
	  	$basename=pathinfo($dir,PATHINFO_BASENAME);
	  	$dir=substr($basename,0,-4);
        $selected[$dir] = $dir==$value ? "selected" : "";
	    $options.="<option value=\"{$dir}\" {$selected[$dir]} >{$dir}</option>\r\n";
	  }

	  return $options;
  }
}
?>